package cn.initcap;

import java.util.ArrayList;
import java.util.List;
import org.apache.flink.api.java.ExecutionEnvironment;

/**
 * @author initcap
 * @date Created in 8/29/19 10:18 AM.
 */
public class DataSetDataSourceJava {

    public static void main(String[] args) throws Exception {
        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

        fromCollection(env);
        fromTextFile(env);
        fromCsvFile(env);

    }

    private static void fromCsvFile(ExecutionEnvironment env) throws Exception {
        String filePath = "/Users/ningzhixue/Public/code/initcap-learn/initcap-flink-core/input/people.csv";
        env.readCsvFile(filePath).ignoreFirstLine().types(String.class, Integer.class, String.class).print();
    }

    private static void fromTextFile(ExecutionEnvironment env) throws Exception {
        String filePath = "/Users/ningzhixue/Public/code/initcap-learn/initcap-flink-core/input/word";
        env.readTextFile(filePath).print();
    }

    private static void fromCollection(ExecutionEnvironment env) throws Exception {
        List<Integer> list = new ArrayList<>(10);
        for (int i = 1; i <= 10; i++) {
            list.add(i);
        }
        env.fromCollection(list).print();
    }

}
